const qss = require('querystring');
//注册一个中间件函数
const bodyCustom = (req, res, next) => {
    let str = '';

    //data函数接收数据
    req.on('data', (chunk) => {
        str += chunk;
    });

    //数据接受完成
    req.on('end', () => {
        console.log(str);
        //自动解析查询字符串转为对象
        const body = qss.parse(str);
        // console.log(body);
        // 把对象转换为查询字符串
        // console.log(qss.stringify(body));
        req.body = body;
        next();
    });

}

module.exports = bodyCustom;